/**
 * <p>Copyright (c) 2011 深圳市鹏途信息技术有限公司 </p>
 * <p>					All right reserved. 		 </p>
 * <p>项目名称 ：   深圳公路信息资源整合及国省检日常化监管管理        </p>
 * <p>创建者   :  John(詹春贤) 
 * <p>描   述  :   省检下的工程建设中的路面材料循环利用控制器    </p>
 * <p>最后修改 :  $: 2017-07-10-下午14:30:00  $     </p>
 * 
*/
package com.pengtu.gsj.controller.checker.gcjs;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.pengtu.gsj.controller.base.CheckTableBaseController;
import com.pengtu.gsj.entity.app.Sysmenu;
import com.pengtu.gsj.entity.check.CheckProject;
import com.pengtu.gsj.entity.check.CheckTable;
import com.pengtu.gsj.interceptor.Token;
import com.pengtu.gsj.service.check.CheckTableService;
import com.pengtu.gsj.service.check.DownService;
import com.pengtu.gsj.service.check.gcjs.RoadMatRecUtilizeService;
import com.pengtu.gsj.service.system.SystemManageService;
import com.pengtu.gsj.service.yh.MainBulletinService;
import com.pengtu.gsj.utils.web.SpringMvcUtils;


/**
 * 
 * RoadMatRecUtilizeController
 * 
 * 2017年7月30日 上午1:12:46
 * 
 * @version 1.0.0
 * 
 */
@Controller
@RequestMapping("roadMatRecUtilize")
public class RoadMatRecUtilizeController  extends CheckTableBaseController {

	@Autowired
	private RoadMatRecUtilizeService roadMatRecUtilizeService;
	@Autowired
	private CheckTableService checkTableService;
	@Autowired
	private SystemManageService systemManageService;
	@Autowired
	private MainBulletinService mainBulletinService;
	@Autowired
	
	private DownService downService;

	@Token(save = true)
	@RequestMapping("show") 
	public String roadMatRecUtilize(Model model){
		//获取提示信息并返回到页面显示
		String msg = SpringMvcUtils.getParameter("msg");
		if (StringUtils.isNotEmpty(msg)) {
			model.addAttribute("msg", msg);
		}
		return "check/proCon/roadMatRecUtilize";
	}
	
	/**
	 * getSearchList:
	 * 适用:ajax请求，根据页面的搜索条件检索数据
	 * @param checkTable
	 * @param checkProject
	 * @param sysmenu
	 * @return 回检索结果
	 * @throws Exception 
	 * @exception 
	 * @since  1.0.0
	*/
	@ResponseBody
	@RequestMapping(value = "search", produces = "application/json; charset=utf-8")
	public Map<String, Object> getSearchList(@ModelAttribute CheckTable checkTable, @ModelAttribute CheckProject checkProject, @ModelAttribute Sysmenu sysmenu) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		//数据信息
		String tag = sysmenu == null ? "" : sysmenu.getTag();
		map = roadMatRecUtilizeService.getRoadMatRecUtilizes(checkProject.getStartTime(), checkProject.getEndTime(), checkTable, tag);
		return map;
	}
	
	/**
	 * 
	 * saveRoadMatRecUtilize:
	 * 适用:保存路面材料回收利用检查表内容，包括搜索条件的存储
	 * @param checkTable
	 * @param checkProject
	 * @param attributes
	 * @return 绑定页面数据（left  parentId projectId menuId） 重定向到检查表页面
	 * @exception 
	 * @since  1.0.0
	 */
	@Token(remove = true)
	@RequestMapping("save")
	public String saveRoadMatRecUtilize(@ModelAttribute CheckTable checkTable, @ModelAttribute CheckProject checkProject, RedirectAttributes attributes){
		checkTable.setCheckProject(checkProject);
		checkTable.setTableFull(checkTable.getYearFull()); //设置当前检查表格的总分
		checkTableService.save(checkTable);
		attributesParams(checkTable, attributes);
		return "redirect:/roadMatRecUtilize/show.do";
	}
	
	/**
	 * downWordAndZip:
	 * 适用:检查表的一键导出，包括检查表的内容及检查条件所对应的附件
	 * @param checkProject
	 * @param checkTable
	 * @param sysmenu
	 * @return 返回打包好的压缩包供用户下载
	 * @throws Exception 
	 * @exception 
	 * @since  1.0.0
	*/
	@ResponseBody
	@RequestMapping("downWord")
	public ResponseEntity<byte[]> downWordAndZip(@ModelAttribute CheckProject checkProject, @ModelAttribute CheckTable checkTable, @ModelAttribute Sysmenu sysmenu) throws Exception {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String tag = sysmenu == null ? "" :sysmenu.getTag();
		String sysName = sysmenu == null ? "" : sysmenu.getName();
		resultMap =  roadMatRecUtilizeService.getRoadMatRecUtilizes(checkProject.getStartTime(), checkProject.getEndTime(), checkTable, tag);
		if ("gcjs_lmclxh".equals(tag)) {
			return downService.downWordAndZip(SpringMvcUtils.getParameter("checkSubmoduleName"), SpringMvcUtils.getParameter("checkModuleName"), sysName, "engConstruction/路面材料循环利用.xml", resultMap);
		}else {
			return downService.downWordAndZip(SpringMvcUtils.getParameter("checkSubmoduleName"), SpringMvcUtils.getParameter("checkModuleName"), sysName, "technicalSupport/路面材料循环利用.xml", resultMap);
		}
	}
}
